<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>预解析</title>
    <script>
      //情况一: Uncaught ReferenceError: num is not defined
      //console.log(num)

      //情况二: undefined
      //let num
      //console.log(num)

      //情况三总结: var会产生变量预解析,而let不会
      //情况三 - 1: Uncaught ReferenceError: can't access lexical declaration 'num' before initialization
      //console.log(num)
      //let num = 5

      //情况三 - 2: undefined
      //原因: 带有var 和 function 声明的变量在内存中会提前声明或者定义 -- 变量或者函数的预解析
      /* console.log(num)
      var num = 5 */

      /* var num
      console.log(num)
      num = 5 */

      //情况四: 正确执行 -- 函数预解析
      fn()
      function fn() {
        console.log('fn()...')
      }

      //情况五: Uncaught TypeError: fn2 is not a function
      /* fn2()
      var fn2 = function () {
        console.log('fn2()...')
      } */
    </script>
  </head>
  <body></body>
</html>
